<template>
  <div class="pb24 uplaodBox page-miH page-bgBack">
    <PageHeader @back="goback" subTitle="返回">{{ query.name }}的{{ query.fieldName }}</PageHeader>
    <div class="topMsg">
      <div class="topMsgs">
        <a-row>
          <a-col :span="12">
            <div class="top">温馨提示</div>
            <div class="bottom">该材料为重要材料，上传重要材料可降低用工风险,最多上传九份</div>
          </a-col>
          <a-col :span="12" style="text-align: right">
            <a-button @click="downloadImg" :disabled="edit != null" style="margin-top: 5px">打包下载</a-button>
            <span style="padding: 0 57px"></span>
          </a-col>
        </a-row>
        <div></div>
      </div>
    </div>

    <div style="padding: 12px; padding-top: 0">
      <Uploading
        ref="operation"
        :multiple="true"
        :fieldCode="query.fieldCode"
        :srcData.sync="accessoryData[query.fieldCode]"
        @change="onFileChange"
        :limit="9"
      ></Uploading>
      <UploadSiteFile
        v-show="false"
        ref="uploadTool"
        :limit="9"
        :default-value="accessoryData[query.fieldCode]"
        accept=".doc, .docx, .xls, .xlsx, .pdf, .zip, .rar, .jpg, .jpeg, .png"
      />
    </div>
  </div>
</template>
<script>
import { getToken } from "xqjr-module-auth";
import { UploadSiteFile } from "xqjr-plugin-common";
import { getEmpFieldValue, empFieldValueSavePut } from "./info/api";
export default {
  components: {
    UploadSiteFile,
    Uploading: () => import("@/components/Uploading/uploadingMaterial")
  },
  props: {},
  data() {
    return {
      accessoryData: {},
      edit: null,
      query: {}
    };
  },
  created() {
    this.query = this.$route.query;
    this.id = this.$store.state.hr.companyId;
    this.getEmpFieldValues();
  },

  methods: {
    // 各项数据源
    getEmpFieldValues() {
      getEmpFieldValue({
        moduleCode: this.query.sign,
        companyId: this.$store.state.hr.companyId,
        empInfoId: this.query.employInfoId
      })
        .then((result) => {
          this.accessoryData = result.data.data;
        })
        .catch((err) => {
          console.log("debug log --> ", err);
        });
    },
    downloadImg() {
      this.$refs.uploadTool.download();
    },
    onFileChange(urls, others) {
      empFieldValueSavePut(
        {
          companyId: this.$store.state.hr.companyId,
          empInfoId: this.query.employInfoId,
          moduleCode: this.query.sign,
          data: { [this.query.fieldCode]: urls }
        },
        "?isVerify=true"
      )
        .then((result) => {
          this.$message.success("修改成功!");
        })
        .catch((err) => {
          console.log("debug log --> ", err);
        })
        .finally(() => {
          this.getEmpFieldValues();
        });
    },
    goback() {
      const that = this;
      if (this.$refs.operation.getReturnOperation()) {
        this.$router.go(-1);
      } else {
        this.$confirm({
          title: "上传附件尚未保存，是否确认离开",
          okText: "确认",
          onOk() {
            that.$router.go(-1);
          }
        });
      }
    },
    pageGetToken() {
      return getToken();
    }
  }
};
</script>
<style lang="scss">
.uplaodBox {
  position: relative;
  .exportTitle {
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    color: #252525;
    .left2 {
      z-index: 3;
      left: 50px;
      position: absolute;
      color: #595959;
      font-size: 16px;
    }
  }
  .anticon-left {
    z-index: 3;
    left: 24px;
    position: absolute;
    color: #d8d8d8;
    font-size: 26px;
    margin-top: 17px;
  }
  .tipBox {
    width: 100%;
    line-height: 35px;
    background: #faf9f9;
    border-radius: 4px;
    margin: 0 0 0 0;
  }

  .ant-modal-body {
    line-height: 24px;

    em {
      color: var(--primary);
      font-style: normal;
    }
  }
}
.img-item {
  padding: 10px;
  border: 1px solid #e8e8e8;
  border-radius: 3px;
  margin-bottom: 10px;
  .imgpart {
    position: relative;
    width: 100%;
    height: 150px;
    overflow: hidden;
    &:hover {
      .shadow-box {
        display: flex;
      }
    }
    .shadow-box {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.5);
      display: none;
      justify-content: center;
      align-items: center;
      z-index: 1;
      i {
        width: 30px;
        height: 30px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        font-size: 16px;
        color: #ffffff;
        line-height: 30px;
        text-align: center;
      }
    }
  }
  .img-info {
    display: flex;
    justify-content: space-between;
    i {
      margin-left: 5px;
    }
  }
}
.topMsg {
  width: 100%;
  height: 80px;
  padding: 0 24px;
  margin: 24px 0;
  .topMsgs {
    width: 100%;
    height: 100%;
    background: #faf9f9;
    border-radius: 4px;
    padding: 18px 15px;
    // display: flex;
    // align-items: center;
    .top {
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #252525;
    }
    .bottom {
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
    }
  }
}
</style>
